﻿using System.Collections;
using System.Drawing;

namespace MathService.Functions.Plotter.GraphComponents
{
    public class Channel
    {
        private readonly Cursor channelCursor;
        private readonly Hashtable points;
        private float currentValue;
        private float cursorOffset;
        private float maximumValue;
        private float minimumValue;
        private int totalTimeElapsed;

        public Channel()
        {
            maximumValue = 100f;
            ChannelColor = Color.Green;
            points = new Hashtable();
            channelCursor = new Cursor(this);
        }

        public Channel(float minValue, float maxValue, string yAxisName)
        {
            maximumValue = 100f;
            ChannelColor = Color.Green;
            points = new Hashtable();
            minimumValue = minValue;
            maximumValue = maxValue;
            YAxisName = yAxisName;
            channelCursor = new Cursor(this);
        }

        public Channel(float minValue, float maxValue, string yAxisName, bool enabled)
        {
            maximumValue = 100f;
            ChannelColor = Color.Green;
            points = new Hashtable();
            minimumValue = minValue;
            maximumValue = maxValue;
            YAxisName = yAxisName;
            Enabled = enabled;
            channelCursor = new Cursor(this);
        }

        public Channel(float minValue, float maxValue, string yAxisName, bool enabled, Color channelColor)
        {
            maximumValue = 100f;
            ChannelColor = Color.Green;
            points = new Hashtable();
            minimumValue = minValue;
            maximumValue = maxValue;
            YAxisName = yAxisName;
            Enabled = enabled;
            ChannelColor = channelColor;
            channelCursor = new Cursor(this);
        }

        public Color ChannelColor { get; set; }

        internal Cursor ChannelCursor { get { return channelCursor; } }

        public float CurrentValue
        {
            get { return currentValue; }
            set
            {
                currentValue = value;
                var tf = new PointF(totalTimeElapsed, currentValue);
                points.Add(points.Count, tf);
                totalTimeElapsed += PlotRate;
            }
        }

        internal float CursorOffset
        {
            get { return cursorOffset; }
            set
            {
                cursorOffset = value;
                maximumValue -= cursorOffset;
                minimumValue += cursorOffset;
            }
        }

        public bool Enabled { get; set; }

        public float MaximumValue { get { return maximumValue; } set { maximumValue = value; } }

        public float MinimumValue { get { return minimumValue; } set { minimumValue = value; } }

        internal int PlotRate { get; set; }

        public Hashtable Points { get { return points; } }

        internal int TotalTimeElapsed { get { return totalTimeElapsed; } set { totalTimeElapsed = value; } }

        public string YAxisName { get; set; }
    }
}
